if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[sp_HangTon_SearchByMaChiNhanh_Mahang]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[sp_HangTon_SearchByMaChiNhanh_Mahang]
go

create proc [sp_HangTon_SearchByMaChiNhanh_Mahang]
	@Ma_chi_nhanh		int,
	@Ma_hang_hoa		int,
	@ID					int OUTPUT
AS
BEGIN
	SELECT @ID = A.ID
	FROM HangTon AS A
	INNER JOIN KhoHang AS B ON A.Ma_kho_hang = B.ID
	WHERE B.Ma_chi_nhanh = @Ma_chi_nhanh AND A.Ma_hang = @Ma_hang_hoa
END